package com.mh.www.mh_frame.view.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.mh.www.mh_frame.R;
import com.mh.www.mh_frame.model.bean.UserBean;
import com.mh.www.mh_frame.presenter.iview.LoginView;
import com.mh.www.mh_frame.presenter.present.impl.LoginPresentImpl;
import com.mh.www.mh_frame.util.ShardPreferencesUtil;
import com.mh.www.mh_frame.util.ToastUtil;
import com.mh.www.mh_frame.view.activity.base.BaseActivity;
import com.mh.www.mh_frame.view.widget.CustomProgressDialog;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author think
 * @version [版本号, 2018/1/19]
 * @see [相关类/方法]
 * @since [V1]
 */

public class LoginActivity extends BaseActivity implements LoginView {

    @BindView(R.id.et_username)
    EditText usernameEt;
    @BindView(R.id.et_pass)
    EditText passEt;
    @BindView(R.id.btn_login)
    Button loginBtn;
    @BindView(R.id.iv_delete)
    ImageView mIvDelete;
    @BindView(R.id.iv_mmm)
    ImageView mIvMmm;
    @BindView(R.id.iv_delete2)
    ImageView mIvDelete2;
    @BindView(R.id.tv_pwd_error)
    TextView mTvPwdError;
    private LoginPresentImpl mLoginPresent;

    @Override
    protected void setContentLayout() {
        setContentView(R.layout.activity_login);
        QMUIStatusBarHelper.translucent(this);
        ButterKnife.bind(this);
    }

    @Override
    public void initView() {
        mLoginPresent = new LoginPresentImpl();
        mLoginPresent.attachView(this);

    }

    @Override
    protected void obtainData() {

    }

    @Override
    protected void initEvent() {
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //判断账号密码是否为空
                mLoginPresent.login();
                //网络请求
                mLoginPresent.getLogin2(getUsername(),getPassword());
            }
        });
    }


    @Override
    public String getUsername() {
        return usernameEt.getText().toString();
    }

    @Override
    public String getPassword() {
        return passEt.getText().toString();
    }

    @Override
    public void clearUsername() {
        usernameEt.setText("");
    }

    @Override
    public void clearPassword() {
        passEt.setText("");
    }

    @Override
    public void showMsg(String msg) {
        ToastUtil.showShortToast(msg);
    }

    @Override
    public void showProgress() {
        CustomProgressDialog.showSuccinctProgress(this, "加载中...", 2, true, true);
    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void usernameIsEmpty() {
        ToastUtil.showShortToast("请输入用户名");
    }

    @Override
    public void passwordIsEmpty() {
        ToastUtil.showShortToast("请输入密码");
    }

    @Override
    public void usernameErro() {

    }

    @Override
    public void passwordErro() {
        mTvPwdError.setVisibility(View.VISIBLE);
    }

    @Override
    public void navigateToHome() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

    @Override
    public void setData(UserBean bean) {
        String eventid = bean.get_Eventid();
        ShardPreferencesUtil.put(this,"id",eventid);
    }
    @Override
    public void setTransparentBar(boolean applyNav) {
        super.setTransparentBar(applyNav);
    }

    @OnClick({R.id.iv_delete, R.id.iv_delete2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_delete:
                clearUsername();
                break;
            case R.id.iv_delete2:
                clearPassword();
                break;
        }
    }
}
